<template>
  <div>
    <modal :show.sync="show"  v-ref:modal big backdrop="false">
      <!--  头部-->
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="close()"><span>&times;</span></button>
        <h5 style="font-size:2;font-weight: bolder;" class="modal-title">抄表修改</h5>
      </header>
      <!--body  -->
      <article slot="modal-body" class="modal-body">
      <div class="app-bg auto">
        <div >
          <span class="col-xs-4">上期指数：</span><span class="col-xs-1">{{row.f_last_tablebase}}</span>
          <span class="col-xs-4">本期指数：</span><span class="col-xs-2"><input v-model='row.f_tablebase' style="width: 60px;"></input></span>
        </div>
        <div>
          <span class="col-xs-4">用气量：</span><span class="col-xs-1">{{row.f_tablebase - row.f_last_tablebase}}</span>
        </div>
      </div>
      </article>
      <!-- 尾部 -->
      <footer slot="modal-footer" class="modal-footer">
        <button v-show="show" type="button" class="btn btn-default" @click='close()'>取消</button>
        <button v-show="show" type="button" class="btn btn-primary" @click='confirm()'>提交</button>
      </footer>
    </modal>
  </div>
</template>
<script>
import co from 'co'
import * as Util from '../Util'
import appData from '../../../src/components/appData'
import config from '../../../src/components/config'
let savetablebase = function * (self){
  //config.resultUrl +
  self.user = [{id:self.row.id,f_tablebase:self.row.f_tablebase,f_last_tablebase:self.row.f_last_tablebase,f_oughtamount:self.row.f_tablebase-self.row.f_last_tablebase,
    f_price_id:self.row.f_price_id,f_meter_state:self.row.f_meter_state,f_remark:self.row.remark}]
  yield self.$resetpost(config.resultUrl + 'rs/logic/savetablebase', {data:{user:self.user,f_input_date:self.model.f_input_date,f_end_date:self.model.f_end_date}},
  {resolveMsg: null, rejectMsg: null})
  .then ((res)=> {
    self.$showMessage('保存成功，已划价')
    self.$emit('msg')
  })
  .catch ((res)=> {
    self.$showMessage('保存失败')
  })
}
export default {
  title: '抄表修改',
  data () {
    return {
      model:{
        f_input_date : Util.toStandardTimeString(),
        f_end_date : Util.addDate (Util.toStandardTimeString(), 60)
      },
      user:[]
    }
  },
  props: ['show', 'row'],
  methods: {
    close () {
      this.show = false
      this.$emit('close')
    },
    confirm () {
      if(this.row.f_tablebase - this.row.f_last_tablebase<0){
        this.$showMessage('本期指数不能小于上期指数')
      }else{
        let gen = savetablebase(this)
        return co(gen)
      }
    }
  }

}

</script>
